package com.hanko.designpattern.singleton;

/**
 * 双重校验
 *对懒汉式单例模式做了线程安全处理增加锁机制
 * volatile变量级
 * synchronized 类级
 * @author hanko
 * @version 1.0
 * @date 2020/9/15 9:53
 */
public class DoubleCheckSingleton {
    //特点一 静态私有变量 不初始化 volatile变量级锁
    private static volatile DoubleCheckSingleton instance;
    //特点二 构造函数私有
    private DoubleCheckSingleton(){

    }
    //特点三 双重null判断  synchronized类级锁
    public static DoubleCheckSingleton getInstance(){
        if (instance == null){
            synchronized(DoubleCheckSingleton.class){
                if (instance == null){
                    instance = new DoubleCheckSingleton();
                }
            }
        }
        return instance;
    }
}
